<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %><%--
  Created by IntelliJ IDEA.
  User: oldliu
  Date: 2022-02-15
  Time: 16:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>日期</title>
    <style>
        p{
            height: 60px;
            border:5px solid red;
            background-color: aqua;
        }
    </style>
</head>
<body>
<%!
    //把日期对象按照指定的格式转换成String
    private static SimpleDateFormat df=new SimpleDateFormat();
    String toString(Date d,String pattern){
        df.applyPattern(pattern);
        return df.format(d);
    }
%>
<h1>方法，把日期转换</h1>
<%
    Date d=new Date();
%>
<p>
    <%=toString(d,"yyyy-MM-dd H:m:s")%>
</p>
<p>
    <%=toString(d,"yyyy/MM/dd")%>
</p>
<p>
    <%=toString(d,"yyyy年MM月dd日")%>
</p>
</body>
</html>
